# ---------------------------------------------------------------------------
# splitFeatures10.py
# Created on: Mon Oct 14 2013 2:40:36 PM
#
# Run in ArcGIS 10
# ---------------------------------------------------------------------------

# Import system modules
import os, arcpy, glob

# Local variables...
inputDir  = "//itacaiunas/E/RAISG/BRASIL/VETORES/UC"
outputDir = "//itacaiunas/E/RAISG/BRASIL/VETORES/UC/#Masks_UC"

folders = [
           "cuencas", 
           "deptales", 
           "nacionales", 
           "paises"
           ]

splitField = "Path_Row"

splitFeatures = "//itacaiunas/E/RAISG/BRASIL/VETORES/RAISG_SHP/Mask_nogap_Clip_wgs84.shp"

clusterTolerance = ""

for i in range(len(folders)):
    inFeatures = glob.glob(inputDir + "/" + folders[i] + '/*.shp')
    outWorkspace = outputDir + "/" + folders[i]

    print 'Split Processing...'    
    for j in range(len(inFeatures)):
        print "Input Feature: ", inFeatures[j]
        
        baseName = os.path.basename(inFeatures[j])
        (shapefileName, extension) = os.path.splitext(baseName)
        
        outWorkspace = outputDir + "/" + folders[i] + "/" + shapefileName
        print "Out Workspace: ", outWorkspace
        if not os.path.exists(outWorkspace):
            os.makedirs(outWorkspace)
        
        # Split Analysis
        arcpy.Split_analysis(inFeatures[j], splitFeatures, splitField, outWorkspace, clusterTolerance)
        
        print "--------------" 

print 'Done!'

